/**
 * Copyright &copy; 2012-2014 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.johnguo.web.home.controller;

import java.util.List;
import java.util.Properties;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.johnguo.common.entity.User;
import com.johnguo.common.entity.UserService;


/**
 * 登录Controller
 */
@Controller
public class LoginController{
	
	protected Logger logger = LoggerFactory.getLogger(getClass());

	/**
	 * 管理登录
	 */
	@RequestMapping(value = "login", method = RequestMethod.GET)
	public ModelAndView login(HttpServletRequest request, HttpServletResponse response, Model model) {
//		
//		String subsysId=request.getParameter("appkey");
//		String name=request.getParameter("usr");
//		
//		User user=authorityDataService.getUser(subsysId, name);
//		List<Menu> rootMenu=user.getRootMenu().getChildList().get(0).getChildList();
		ModelAndView mv = new ModelAndView("home/home");
//		mv.addObject("userDomain", user);
//		mv.addObject("menuList", rootMenu);
		mv.addObject("logoImg", "logo_heyuan.png");
		mv.addObject("user", UserService.getUser());
		return mv;
	}

	/**
	 * 登录成功，进入管理首页
	 */
	/*@RequiresPermissions("equip:view:add")*/
	@RequestMapping(value = "index")
	public ModelAndView index(HttpServletRequest request, HttpServletResponse response) {
		
//		
//		String subsysId=request.getSession().getAttribute("appkey").toString();
//		String name=((Principal)SecurityUtils.getSubject().getPrincipal()).getLoginName();
//		
//		User user=authorityDataService.getUser(subsysId, name);
//		List<Menu> rootMenu=user.getRootMenu().getChildList().get(0).getChildList();
//		
//		Area area=user.getArea();
//		//TODO 暂时注掉
////		NodeUtil root = new NodeUtil(area.getId(), area.getParentId(), area.getName(),true,area.getType());
//		NodeUtil root = new NodeUtil(area.getId(), area.getParentId(), area.getName(),true);
//		
//		
//		NodeUtil result=NodeUtil.getAreaJson(root,area);
//		JSONArray obj = JSONArray.fromObject(result);
//		
//		String ids=area.getId();
//		ids=NodeUtil.getIds(ids,area);
//		ids=ids.substring(0, ids.lastIndexOf(","));
//		
//		SecurityUtils.getSubject().getSession().setAttribute("areaJson", obj.toString());
//		SecurityUtils.getSubject().getSession().setAttribute("areaIds", ids);
//		
//		Properties propertiesUtils = SpringContextHolder.getBean("propertiesUtil");
//		String logoImg = propertiesUtils.getProperty("images.logo");
		ModelAndView mv = new ModelAndView("home/home");
//		mv.addObject("userDomain", user);
//		mv.addObject("menuList", rootMenu);
		mv.addObject("logoImg", "logo_heyuan.png");
		mv.addObject("user", UserService.getUser());
//		//TODO 暂时注掉
////		NodeUtil root_query = new NodeUtil(area.getId(), area.getParentId(), area.getName(),true,area.getType());
//		NodeUtil root_query = new NodeUtil(area.getId(), area.getParentId(), area.getName(),true);
//		if("1".equals(area.getType()) || "2".equals(area.getType())){
//			//TODO 暂时注掉
////			NodeUtil result_query=NodeUtil.getAreaJson_query(root_query,area);
//			NodeUtil result_query=NodeUtil.getAreaJson(root_query,area);
//			SecurityUtils.getSubject().getSession().setAttribute("areaJson_query", JSONArray.fromObject(result_query).toString());
//		}else if("3".equals(area.getType())){
//			SecurityUtils.getSubject().getSession().setAttribute("areaJson_query", obj.toString());
//		}else{
//			SecurityUtils.getSubject().getSession().setAttribute("areaJson_query",null);
//		}
		return mv;
	}

	
}
